<template>
  <div class="items">
    <h5 class="title">推荐商品</h5>
    <div class="item" v-for="item in items" :key="item.id" @click="clickItem(item.id)">
      <img :src="item.pic" alt="" class="item-img" />
      <div class="item-info">
        <h5>{{ item.name }}</h5>
        <div class="item-action">
          <span class="price">￥{{ item.minPrice }}</span>
          <van-icon
            name="gouwuchetianjia"
            size="18"
            color="#0ED397"
            class-prefix="icon"
            @click.stop="addCart(item.id)"
          ></van-icon>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { defineProps, defineEmits } from "vue";
const props = defineProps<{
  items: { id: number; name: string; minPrice: number; pic: string }[];
}>();
const emit = defineEmits<{
  (e: "clickItem", id: number): void;
  (e: "clickAddIcon", id: number): void;
}>();
const clickItem = (id: number) => {
  // 点击id
  emit("clickItem", id);
};
// 点击加入购物车图标
const addCart = (id: number) => {
  emit("clickAddIcon", id);
};
</script>

<style lang="scss" scoped>
.items {
  .title {
    font-size: 16px;
    line-height: 30px;
    text-align: center;
    background-color: #f9f6f6;
  }
  .item {
    display: flex;
    padding: 0 8px;
    margin-top: 5px;
    &-img {
      width: 4rem;
    }
    &-info {
      flex: 1;
      padding-left: 8px;

      h5 {
        font-size: 14px;
        line-height: 30px;
      }
      .item-action {
        display: flex;
        justify-content: space-between;
        .price {
          font-size: 18px;
          color: #0ed397;
        }
      }
    }
  }
}
</style>
